#p111
owels = ["a","e","i","o","u"]
word = input("Provide a word to search for vowels:")
found = {} # 创建一个空字典

found["a"]=0
found["e"]=0
found["i"]=0
found["o"]=0
found["u"]=0   #初始化关联值


for letter in word:
    if letter in vowels:
        found[letter] += 1
for k,v in sorted(found.items()):  # sorted函数用来控制输出顺序
    print(k,"was found",v,"time(s).")



# p121练习
vowels = ["a","e","i","o","u"]
word = input("Provide a word to search for vowels:")
found = {}

   # 去掉繁琐的初始化环节

for letter in word:
    if letter in vowels:
        found.setdefault(letter, 0)  # 调用setdefault函数 保证把一个不存在的键初始化为一个指定默认值
        found[letter] += 1
for k,v in sorted(found.items()):
    print(k,v)


# 集合改进代码  vowels7.py
vowels = set('aeiou')   # 替换vowels = ["a","e","i","o","u"]
word = input("Provide a word to search for vowels:")

found = vowels.intersection(set(word))

#found = {}

# 去掉繁琐的初始化环节

#for letter in word:
 #   if letter in vowels:
  #      if letter not in found:
   #         found.append(letter)
for vowel in found:
    print(vowel)


# 嵌套字典
import pprint  # 引入pprint模块 功能：美化输出格式
people = {}
people['Ford'] = {"Name":'Ford Prefect',
                   "Gender":'Male',                   "Occupation":'Researcher',
                   "Home Planet":'Betelgeuse Seven'}
people['Arthur'] = {"Name":'Arthur Dent',
                    "Gender":'Male',
                    "Occupation":'Sandwich-Maker',
                    "Home Planet":'Earth'}
people['Tricia'] = {"Name":'Tricia McMillan',
                    "Gender":'Female',
                    "Occupation":'Mathematician',
                    "Home Planet":'Earth'}
people['Marvin'] = {"Name":'Marvin',
                    "Gender":'Unknown',
                    "Occupation":'Paranoid Android',
                    "Home Planet":'Unknown'}
pprint.pprint(people)